
<template>
  <div style="height:100%;width:100%;position:relative;">
      <div class="pagetop">
          <div class="search-title" style="top:10px">快速查询</div>
          <div class="search-title" style="top:5px">
              <el-input v-model="txtsearch" placeholder="名称|代码|级别:菌科0菌属1细菌2" style="padding-left:55px;width:240px"></el-input>
          </div>
          <div style="padding-left:250px;height: 90px;">
              <el-tag style="height: 90px;width:100%;font-size:14px;font-weight:550">1.选择上级类别下级所有细菌全部默认遵守此规则。
                  <br style="padding-left:10px">{{etestmethodmodifymic=='1'?'2.当使用Etest法试验时，仍沿用MIC法参数。':'2.当使用Etest法试验时，仍沿用KB法参数。但是设置的【KB耐药】取值要大于【KB敏感】取值。'}}<br style="padding-left:10px">3.KB法,MIC法的耐药、敏感默认采用&lt;=、&gt;=，若想设置&lt;、&gt;请在取值栏手动输入&lt;、&gt;。
              <br style="padding-left:10px">4.Ecv，数值设置在mic敏感和kb敏感中，使用mic法检测时，&lt;=mic敏感值判定为野生型，使用kb法检测时，&gt;=kb敏感值判定为野生型
              </el-tag>
          </div>
          <!-- <div class="search-title" style="color:blue">提示:选择上级类别下级所有细菌全部默认遵守此规则。</div> -->
          <div class="top-deal">
              <el-button @click="btnQuery" icon="el-icon-search" type="primary" v-has="'PINQUERY'" :disabled="bChangeFlag">查询</el-button>
              <el-button @click="btnmedCopy" icon="el-icon-document"  :disabled="bChangeFlag">复制</el-button>
              <el-button @click="btnAdd" icon="el-icon-plus" v-has="'PADD'" :disabled="bChangeFlag">新增</el-button>
              <el-button @click="btnDel" icon="el-icon-delete" v-has="'PDELETE'" :disabled="bChangeFlag">删除</el-button>
              <el-button @click="btnSaveTip" icon="el-icon-document" v-has="'PMODIFY'" :disabled="!bChangeFlag">保存</el-button>
              <el-button @click="btnClear" icon="el-icon-close" :disabled="!bChangeFlag">取消</el-button>
              <!-- <el-button @click="btnExport" icon="el-icon-upload2">导出</el-button> -->
              <!-- <el-button @click="btnImport" icon="el-icon-download">导入</el-button> -->
          </div>
      </div>
      <div class="pagecenter">
          <rm-layout-right splitcolor="#ffffff" movingcolor="#ccffff" :splitwidth="5" :fixsize="800" :minfixsize="80">
              <vxe-table :data.sync="list" :loading="bLoading" :row-class-name="LRowClassName" :cell-class-name="lCellClassName" :select-config="selectConfig" :sort-config="{trigger: 'cell'}" :edit-config="{trigger: 'click', mode: 'cell',showStatus: true,showIcon:false}" @current-change="CurrentChangeEvent" fit height="auto" header-align="center" highlight-current-row highlight-hover-row highlight-hover-column border ref="lXTable" resizable show-header-overflow="tooltip" show-overflow="tooltip" size="mini" stripe class="detailxTable" :keyboard-config="keyConfig" :keyboard-local-config="keyLocalConfig" @edit-disabled="editDisabledEvent">
                  <!-- <vxe-table-column title="细菌"> -->
                  <vxe-table-column type="index" title="NO." align="center" width="7%"></vxe-table-column>
                  <vxe-table-column field="germkindna" title="菌科" width="32%" sortable :disabled="true" :edit-render="{name: 'input',autoselect: true}">
                      <template v-slot:edit="{ row,column }">
                          <el-input placeholder="双击开窗" v-model="row.germkindna" style="width:100%; color:blue" @keyup.space.native="OpenGermDlg(row,1)" @dblclick.native="OpenGermDlg(row,1)" readonly>
                          </el-input>
                      </template>
                  </vxe-table-column>
                  <vxe-table-column field="germgroupna" title="菌属" width="31%" sortable :disabled="true" :edit-render="{name: 'input',autoselect: true}">
                      <template v-slot:edit="{ row,column }">
                          <el-input placeholder="双击开窗" v-model="row.germgroupna" style="width:100%; color:blue" @keyup.space.native="OpenGermDlg(row,2)" @dblclick.native="OpenGermDlg(row,2)" readonly>
                          </el-input>
                      </template>
                  </vxe-table-column>
                  <vxe-table-column field="germna" title="细菌" width="32%" sortable :disabled="true" :edit-render="{name: 'input',autoselect: true}">
                      <template v-slot:edit="{ row,column }">
                          <el-input placeholder="双击开窗" v-model="row.germna" style="width:100%" @keyup.space.native="OpenGermDlg(row,3)" @dblclick.native="OpenGermDlg(row,3)" readonly>
                          </el-input>
                      </template>
                  </vxe-table-column>
                  <vxe-table-column field="isgermgroup" title="级别" width="50px" sortable :disabled="true">
                  </vxe-table-column>
                  <vxe-table-column field="orgcode" title="细菌类代码" width="120px" sortable :disabled="true" customs="false">
                  </vxe-table-column>
                  <!-- </vxe-table-column> -->
              </vxe-table>
              <template v-slot:fix>
                  <!-- <div class="middle-right" v-loading="bPageInitLoading" element-loading-spinner="el-icon-loading" element-loading-background="rgba(0, 0, 0, 0.8)"> -->
                  <vxe-table :data="rXTableData" :loading="bLoading" :select-config="selectConfig" :sort-config="{trigger: 'cell'}" :edit-config="{trigger: 'click', mode: 'cell',showStatus: true,activeMethod:activeMethod,showIcon:false}" fit border height="auto" header-align="center" highlight-current-row highlight-hover-row highlight-hover-column ref="rXTable" resizable show-header-overflow="tooltip" show-overflow="tooltip" size="mini" stripe :row-class-name="RRowClassName" :edit-rules="dept_validRules" :keyboard-config="keyConfig" :keyboard-local-config="keyLocalConfig">
                      <!-- <vxe-table-column title="抗生素"> -->
                      <vxe-table-column type="index" title="NO." align="center" width="6%"></vxe-table-column>
                      <vxe-table-column field="medname" title="药物名称(双击开窗)" width="160" sortable :disabled="true" :edit-render="{name: 'input',autoselect: true}">
                          <template v-slot:header="{column}">
                              <span style="color:#F56C6C;">药物名称(双击开窗)</span>
                          </template>
                          <template v-slot:edit="{ row,column }">
                              <el-input placeholder="双击开窗" v-model="row.medname" style="width:100%" @keyup.space.native="OpenMedDlg(row,1)" @keyup.enter.native="GoTopMedGroup(row)" @dblclick.native="OpenMedDlg(row,1)" readonly>
                              </el-input>
                          </template>
                      </vxe-table-column>
                      <vxe-table-column field="testmethod" title="测试方法" width="80" :edit-render="{name: 'select',options:$opt.testmethod}" align='center'>
                          <template v-slot:header="{column}">
                              <span style="color:#F56C6C;">测试方法</span>
                          </template>
                      </vxe-table-column>
                      <vxe-table-column field="guidelines" title="使用标准" :edit-render="{name: 'input',events: {change: HasChange},autoselect:true}" width="80" align='center'></vxe-table-column>
                      <vxe-table-column field="potency" title="药物浓度" :edit-render="{name: 'input',events: {change: HasChange},autoselect:true}" width="100" align='center'></vxe-table-column>
                      <vxe-table-column field="kbny" title="KB耐药<=" :edit-render="{name: 'input',events: {change: CalcRange},autoselect:true}"  width="60" align='center'>
                      </vxe-table-column>
                      <vxe-table-column field="kbmg" title="KB敏感>=" :edit-render="{name: 'input',events: {change: CalcRange},autoselect:true}" width="60" align='center'>
                      </vxe-table-column>
                      <vxe-table-column field="kbzj" title="KB中敏" :edit-render="{name: 'input',events: {change: HasChange},autoselect:true}" width="80" align='center'></vxe-table-column>
                      <vxe-table-column field="micny" title="MIC耐药>=" :edit-render="{name: 'input',events: {change: CalcRange},autoselect:true}" width="60" align='center'>
                      </vxe-table-column>
                      <vxe-table-column field="micmg" title="MIC敏感<=" :edit-render="{name: 'input',events: {change: CalcRange},autoselect:true}" width="60" align='center'>
                      </vxe-table-column>
                      <vxe-table-column field="miczj" title="MIC中敏" :edit-render="{name: 'input',events: {change: HasChange},autoselect:true}" width="89" align='center'></vxe-table-column>
                      <vxe-table-column field="kbrange" title="KB参考范围" :edit-render="{name: 'input',events: {change: HasChange},autoselect:true}" width="89" align='center'></vxe-table-column>
                      <vxe-table-column field="micrange" title="MIC参考范围" :edit-render="{name: 'input',events: {change: HasChange},autoselect:true}" width="109" align='center'></vxe-table-column>
                      <vxe-table-column field="ecvs" title="流行病学界值" :edit-render="{name: 'input',events: {change: HasChange},autoselect:true}" width="109" align='center'></vxe-table-column>
                      <vxe-table-column field="i2sdd" title="中介转换为SDD" width="100" align="center">
                          <template v-slot="{row}">
                              <el-checkbox v-model="row.i2sdd" true-label='1' false-label="0" @change="HasChange"></el-checkbox>
                          </template>
                      </vxe-table-column>
                      <vxe-table-column field="isimportant" title="是否重点抗生素" width="100" align="center">
                          <template v-slot="{row}">
                              <el-checkbox v-model="row.isimportant" true-label='1' false-label="0" @change="HasChange"></el-checkbox>
                          </template>
                      </vxe-table-column>
                      <vxe-table-column field="medcode" title="药物代码" width="80"></vxe-table-column>
                      <vxe-table-column field="specimen_code" title="标本类型(双击开窗)" width="150">
                          <template v-slot="{row}">
                              <rm-ddl-common ref="ddlspecimen" datatype="specimenaddall" dataname="标本类型" v-model="row.specimen_code" width="150px" @change="HasChange"></rm-ddl-common>
                              <!-- <el-input v-model="row.specimen_code" width="150px" @dblclick="openSpecDlg"></el-input>  -->
                          </template>
                      </vxe-table-column>
                      <vxe-table-column field="medremarks" title="备注" width="350">
                          <template v-slot="{row}">
                              <el-input v-model="row.medremarks" type="textarea" autosize @change="HasChange"></el-input>
                          </template>
                      </vxe-table-column>
                      <template v-slot:fix>
                          <div style="font-size:17px;padding:3px;background-color:#fff;overflow:auto;text-align:left">
                              <el-button class="el-button--310" @click="OpenDialog(1)">新增明细</el-button>
                              <el-button class="el-button--310" @click="OpenDialog(2)">删除明细</el-button>
                              <el-button class="el-button--310" @click="copyPaste(1)">复制</el-button>
                              <el-button class="el-button--310" @click="copyPaste(2)">粘贴</el-button>
                          </div>
                      </template>
                  </vxe-table>
              </template>
          </rm-layout-right>
      </div>
      <!--菌科弹窗-->
      <el-dialog v-el-drag-dialog :append-to-body="true" :close-on-click-modal="false" title="请选择菌科" :visible.sync="bDlgGermkind" :show-close="true" :destroy-on-close="true" v-if="diagx">
          <rm-pop-common ref="refGermkind" @change="GermKindChange" @cancel="bDlgGermkind=false;diagx=false;" datatype="labgermkind"></rm-pop-common>
      </el-dialog>
      <!--菌属弹窗-->
      <el-dialog v-el-drag-dialog :append-to-body="true" :close-on-click-modal="false" title="请选择菌属" :visible.sync="bDlgGermgroup" :show-close="true" :destroy-on-close="true" v-if="diagx">
          <rm-pop-common ref="refGermgroup" @change="GermGroupChange" @cancel="bDlgGermgroup=false;diagx=false;" datatype="germgroup"></rm-pop-common>
      </el-dialog>
      <!--细菌弹窗-->
      <el-dialog v-el-drag-dialog :append-to-body="true" :close-on-click-modal="false" title="请选择细菌" :visible.sync="bDlgGerm" :show-close="true" :destroy-on-close="true" v-if="diagx">
          <rm-pop-common ref="refGerm" @change="GermChange" @cancel="bDlgGerm=false;diagx=false;" datatype="germ"></rm-pop-common>
      </el-dialog>
      <!--抗生素弹窗-->
      <el-dialog v-el-drag-dialog :append-to-body="true" :close-on-click-modal="false" title="请选择抗生素" :visible.sync="bDlgMed" :show-close="true" :destroy-on-close="true" v-if="diagx">
          <rm-pop-common ref="refMed" @change="MedChange" @cancel="bDlgMed=false;diagx=false;" :kindno="kindno" :param1="param1" :stopflag="stopflag"  datatype="med"></rm-pop-common>
      </el-dialog>
  </div>

</template>

<script type="text/javascript">
import XEUtils from "xe-utils";
export default {
  name: "LIS823",
  data() {
      return {
          txtsearch: "",
          actionindex: "M",
          stopflag:"1",
          param1: "", //pop组件用
          kindno: "", //pop组件用
          oldRowId: "",
          newRowId: "",
          diagx: false, //销毁弹窗数据
          bLoading: false,
          bPageInitLoading: false,
          bChangeFlag: false,
          //弹窗组件-细菌
          bDlgGermkind: false,
          bDlgGermgroup: false,
          bDlgGerm: false,
          //弹窗组件-抗生素
          bDlgMed: false,
          ntempRow: {},
          tempRow: {},
          germRow: {},
          medRow: {},
          keyLocalConfig: {
              isArrow: true,
          },
          keyConfig: {
              isDel: true,
              isTab: true,
              isEdit: true,
          },
          selectConfig: { tigger: "row" },
          dept_validRules: {
              medcode: [{ required: true, message: "药物代码必须填写" }],
              testmethod: [{ required: true, message: "测试方法必须填写" }],
              // orgcode: [{ required: true, message: "科室代码(HIS)必须填写" }],
          },
          selrow: [],
          AddData: [],
          ModData: [],
          lXTableData: [],
          rXTableData: [],
          TplXTableData: [],
          medGroupOptions: [
              { value: "", label: "请选择" },
              { value: "A", label: "A组" },
              { value: "B", label: "B组" },
              { value: "C", label: "C组" },
              { value: "U", label: "U组" },
              { value: "O", label: "O组" },
          ],
          copyMedlist: [],
          micrange:"",
          kbrange:"",
          etestmethodmodifymic :"0",
      };
  },
  created() {
      this.initpage();
      this.btnQuery();
  },
  watch: {
      txtsearch(val) {
          let row = this.list[0];
          if (row) {
              this.HightLightRow(row);
          } else {
              this.HightLightRow(false);
          }
      },
  },
  computed: {
      //模糊查询  名称|代码|级别:菌科1菌属2细菌3
      list() {
          let filterName = this.txtsearch.trim();
          if (filterName) {
              let rest = this.lXTableData.filter((item) => {
                  return item.orgcode.toUpperCase().indexOf(filterName.toUpperCase()) > -1 || (item.inputcode ? item.inputcode.toUpperCase().indexOf(filterName.toUpperCase()) > -1 : false) || (item.germkindna ? item.germkindna.toUpperCase().indexOf(filterName.toUpperCase()) > -1 : false) || (item.germgroupna ? item.germgroupna.toUpperCase().indexOf(filterName.toUpperCase()) > -1 : false) || (item.germna ? item.germna.toUpperCase().indexOf(filterName.toUpperCase()) > -1 : false) || item.isgermgroup.toUpperCase().indexOf(filterName.toUpperCase()) > -1;
              });
              return rest;
          } else {
              return this.lXTableData;
          }
      },
  },
  mounted() {},
  updated() {},
  methods: {
      //------------------编辑类 ------------------//
      activeCellMethod({ column, columnIndex }) {
          return columnIndex !== 1;
      },
      activeRowMethod({ row, rowIndex }) {
          return rowIndex !== 1;
      },
      editDisabledEvent({ row, column }) {
          this.$XMsg.alert("禁止编辑");
      },
      initpage(){
          this.$tool
              .request({
                  url: "LIS/LIS8/LIS823",
                  method: "post",
                  data: {
                      action: "initpage",
                  },
              }).then((res)=>{
                  this.micrange = res.micrange;
                  this.kbrange = res.kbrange;
                  this.etestmethodmodifymic = res.etestmethodmodifymic;
              })
      },
      //----------------- 查询类 ----------------- //
      //主表查询
      btnQuery() {
          this.AddData = [];
          this.ModData = [];
          this.bLoading = true;
          this.$tool
              .request({
                  url: "LIS/LIS8/LIS823",
                  method: "post",
                  data: {
                      action: "btn_query_germ",
                  },
              })
              .then((res) => {
                  this.lXTableData = res.RData.Data;
                  this.TplXTableData = XEUtils.clone(res.RData.Data, true);
                  if (this.lXTableData.length == 0) this.actionindex = "A";
                  if (this.actionindex == "C") {
                      // this.HightLightRow(this.tempRow)
                      this.actionindex = "M";
                  } else {
                      this.HightLightRow(res.RData.Data[0]);
                      // this.orgcode = res.RData.Data[0].orgcode
                  }

                  this.bLoading = false;
              })
              .catch((err) => {
                  this.bLoading = false;
              });
      },
      //明细查询 -- 主表，子表
      async detailQuery(row) {
          try {
              this.selrow = row;
              this.rXTableData = [];
              setTimeout(() => {
                  this.tempRow = XEUtils.clone(row, true);
                  if (row._XID != null) {
                      this.oldRowId = XEUtils.clone(row._XID, true);
                  } else this.oldRowId = [];
              }, 10);
              this.actionindex = "M";
              this.bPageInitLoading = true;
              const res = await this.$tool.request({
                  url: "LIS/LIS8/LIS823",
                  method: "post",
                  data: {
                      action: "btn_query_medgroup",
                      isgermgroup: row.isgermgroup == 0 ? "" : row.isgermgroup,
                      orgcode: row.orgcode,
                  },
              });
              if (res.data.length > 0) {
                  this.rXTableData = res.data;
                  this.$refs.rXTable.setCurrentRow(this.rXTableData[0]);
              } else {
                  this.rXTableData = [];
              }
              this.bPageInitLoading = false;
          } catch (e) {
              this.bPageInitLoading = false;
              this.$message.error(e);
          }
      },
      GKind(germ, germgroup) {
          this.$tool
              .request({
                  url: "LIS/LIS8/LIS823",
                  method: "post",
                  data: {
                      action: "ddl_germkind",
                      germ: germ,
                      germgroup: germgroup,
                  },
              })
              .then((res) => {
                  if (res.data.length > 0) {
                      this.germRow.germkind = res.data[0].germkindcode;
                      this.germRow.germkindna = res.data[0].germkindname;
                  } else {
                      this.germRow.germkind = "";
                      this.germRow.germkindna = "";
                  }
              });
      },
      GGroup(germ) {
          this.$tool
              .request({
                  url: "LIS/LIS8/LIS823",
                  method: "post",
                  data: {
                      action: "ddl_germgroup",
                      germ: germ,
                  },
              })
              .then((res) => {
                  if (res.data.length > 0) {
                      this.germRow.germgroup = res.data[0].rpt_itemcode;
                      this.germRow.germgroupna = res.data[0].rpt_itemname;
                  } else {
                      this.germRow.germgroup = "";
                      this.germRow.germgroupna = "";
                  }
              });
      },
      //----------------- 按钮类 -----------------//
      //新增
      btnAdd() {
          // this.bChangeFlag = true
          this.actionindex = "A";
          this.$refs.lXTable.insertAt({ newrow: 1 }, -1);
          this.FunscrollY();
          this.rXTableData = [];
          this.$nextTick(() => {
              this.$refs.rXTable.insertAt({ i2sdd: 0, isgermkind: null, orgcode: null, isgermgroup: 0 }, -1);
              this.$refs.rXTable.updateListenter();
          });
          this.bChangeFlag = true;
      },
      // //删除 -- 弹窗提示
      btnDel() {
          var name = this.tempRow.isgermgroup == "2" ? this.tempRow.germkindna : this.tempRow.isgermgroup == "1" ? this.tempRow.germgroupna : this.tempRow.germna;
          this.$confirm("您确定要删除<span style='color:red;font-weight: 700'>" + name + "</span>的所有抗生素折点吗？", {
              confirmButtonText: "确定",
              cancelButtonText: "取消",
              type: "warning",
              dangerouslyUseHTMLString: true,
          })
              .then(() => {
                  this.actionindex = "D";
                  this.confirmDel();
              })
              .catch(() => {});
      },
      //删除 -- 确认删除
      async confirmDel() {
          try {
              var delrow = this.$refs.lXTable.getCurrentRow();
              if (delrow) {
                  var alld = this.$refs.lXTable.tableData;
                  var rowindex = alld.indexOf(delrow);
                  this.$refs.lXTable.remove(delrow);
                  await this.btnSave().then(() => {
                      // this.lXTableData.splice(rowindex, 1)
                      let havedata = this.$refs.lXTable.tableData;
                      console.log("confirmDel -> havedata", havedata);
                      if (havedata.length > 0) {
                          if (rowindex >= havedata.length) rowindex = havedata.length - 1;
                          let selectrow = havedata[rowindex];
                          console.log("confirmDel -> selectrow", selectrow);
                          this.HightLightRow(selectrow);
                      } else {
                          this.HightLightRow(false);
                      }
                  });
              }
          } catch (e) {
              this.$message.error(e);
          }
      },
      //取消 -- 取消操作，数据还原
      btnClear() {
          this.$confirm("您确定要取消这次改动吗？", {
              confirmButtonText: "确定",
              cancelButtonText: "取消",
              type: "warning",
          })
              .then(() => {
                  this.bChangeFlag = false;
                  this.lXTableData = XEUtils.clone(this.TplXTableData, true);
                  if (this.actionindex == "A") {
                      setTimeout(() => {
                          let last = this.$refs.lXTable.tableData[this.$refs.lXTable.tableData.length - 1];
                          this.$refs.lXTable.setCurrentRow(last);
                          this.detailQuery(last);
                      }, 30);
                  } else {
                      let a = this.lXTableData.filter((item) => item.isgermgroup == this.tempRow.isgermgroup && item.orgcode == this.tempRow.orgcode);
                      setTimeout(() => {
                          this.tempRow._XID = a[0]._XID;
                          this.$refs.lXTable.setCurrentRow(this.tempRow);
                          this.detailQuery(this.tempRow);
                      }, 30);
                  }
                  this.actionindex = "C";
              })
              .catch(() => {});
      },
      //保存 -- 保存新增，修改，删除主表: lab_medgroup 子表: lab_medgroupdetail 操作//
      btnSaveTip() {
          if (this.$refs.rXTable.tableData.length < 1) {
              this.$confirm("当前细菌类下无药物,所选细菌类将会被删除。您确定要执行此操作吗？", {
                  confirmButtonText: "确定",
                  cancelButtonText: "取消",
                  type: "warning",
              })
                  .then(() => {
                      this.btnSave();
                  })
                  .catch(() => {
                      this.$message.info("取消保存");
                  });
          } else {
              this.btnSave();
          }
      },
      qcsValid() {
          var msg; //校验表头数据
          if (msg) return msg;
          //校验明细数据
          var record = this.$refs.rXTable.tableData;
          for (let i = 0, len = record.length; i < len; i++) {
              msg = this.valid(record[i].medname, "保存失败：第" + (i + 1) + "行 药物名称 未选择");
              if (msg) return msg;
              msg = this.valid(record[i].testmethod, "保存失败：第" + (i + 1) + "行 测试方法 未选择！");
              if (msg) return msg;
          }
      },
      //自制必填校验函数，以后待扩展
      valid(obj, message) {
          if (XEUtils.isUndefined(obj)) {
              return this.$message({
                  message: message,
                  type: "warning",
              });
          }
          if (XEUtils.isNull(obj)) {
              return this.$message({
                  message: message,
                  type: "warning",
              });
          }
          if (XEUtils.isString(obj)) {
              if (!XEUtils.getSize(obj) > 0) {
                  return this.$message({
                      message: message,
                      type: "warning",
                  });
              }
          }
          if (XEUtils.isDate(obj)) {
              if (obj < XEUtils.toStringDate("2000-01-01")) {
                  return this.$message({
                      message: message,
                      type: "warning",
                  });
              }
          }
      },
      async btnSave() {
          if (this.qcsValid()) return false;
          let oOrgcode = this.tempRow.orgcode;
          let oIsgermgroup = this.tempRow.isgermgroup == "2" ? 1 : 0;
          console.log("🐘🐘🐘🐘🐘 —— oIsgermgroup", oIsgermgroup);
          let nOrgcode = "";
          let nIsgermgroup = 0;
          // //通过_XID获取修改后的代码和级别
          this.$refs.lXTable.getRowById(this.oldRowId);
          if (this.$refs.lXTable.getRowById(this.oldRowId) != null) {
              nOrgcode = this.$refs.lXTable.getRowById(this.oldRowId).orgcode;
              nIsgermgroup = this.$refs.lXTable.getRowById(this.oldRowId).isgermgroup;
          } else {
              //获取新增细菌代码 及 级别
              nOrgcode = this.ntempRow.orgcode;
              nIsgermgroup = this.ntempRow.isgermgroup;
          }
          let medArr = this.$refs.rXTable.getTableData().fullData;
          // var insrtarr = this.$refs.rXTable.getRecordset();
          let insrtArr = [];
          if (this.actionindex != "D") {
              medArr.forEach((e) => {
                  let orgcode = nOrgcode;
                  let isgermkind = nIsgermgroup == "2" ? 1 : 0;
                  let s = {
                      // medname: e.medname,
                      medcode: e.medcode,
                      testmethod: e.testmethod,
                      guidelines: e.guidelines,
                      potency: e.potency,
                      kbny: e.kbny,
                      kbmg: e.kbmg,
                      kbzj: e.kbzj,
                      micny: e.micny,
                      micmg: e.micmg,
                      miczj: e.miczj,
                      kbrange: e.kbrange,
                      micrange: e.micrange,
                      ecvs: e.ecvs,
                      i2sdd: e.i2sdd,
                      medcode: e.medcode,
                      specimen_code: e.specimen_code,
                      ddlspecimen: e.ddlspecimen,
                      orgcode: orgcode,
                      isgermkind: isgermkind,
                      isimportant : e.isimportant,
                      medremarks: e.medremarks,
                  };
                  insrtArr.push(s);
              });
          }
          // if (this.actionindex == "A") {
          //     insrtarr.insertRecords.forEach((element) => {
          //         element.orgcode = nOrgcode;
          //         element.isgermkind = nIsgermgroup == "2" ? 1 : 0;
          //     });
          // }
          try {
              const res = await this.$tool.request({
                  url: "LIS/LIS8/LIS823",
                  method: "post",
                  data: {
                      action: "btn_save",
                      // insrtarr: this.$refs.rXTable.getRecordset(),
                      insrtarr: insrtArr,
                      act: this.actionindex,
                      oOrgcode: oOrgcode,
                      oIsgermgroup: oIsgermgroup,
                  },
              });
              if (res.errcode == "1") {
                  this.$message.success("保存成功！");
                  this.$refs.lXTable.updateListenter();
                  this.bChangeFlag = false;
                  if (this.actionindex == "A") {
                      if (this.AddData.indexOf(nOrgcode) == -1) {
                          this.AddData.push(this.tempRow);
                      }
                      let tabledata = this.$refs.lXTable.updateData();
                      this.tempRow = this.$refs.lXTable.getCurrentRow();
                      this.detailQuery(this.$refs.lXTable.getCurrentRow());
                      // this.actionindex = 'M'
                      // this.detailQuery(this.selrow)
                  } else if (this.actionindex == "M") {
                      if (this.ModData.indexOf(oOrgcode) == -1) this.ModData.push(this.$refs.lXTable.getRowById(this.oldRowId));
                      if (this.$refs.rXTable.tableData.length < 1) {
                          var alld = this.$refs.lXTable.tableData;
                          var rowindex = alld.indexOf(this.selrow);
                          console.log("rowindex", rowindex);
                          this.$refs.lXTable.remove(this.selrow);
                          let havedata = this.$refs.lXTable.getTableData().fullData;
                          console.log();
                          if (havedata.length > 0) {
                              if (rowindex >= havedata.length) rowindex = havedata.length - 1;
                              let selectrow = havedata[rowindex];
                              this.HightLightRow(selectrow);
                          } else {
                              this.HightLightRow(false);
                          }
                      }
                      this.detailQuery(this.$refs.lXTable.getCurrentRow());
                  } else {
                      this.actionindex = "M";
                  }
                  if (this.$refs.rXTable.tableData.length == 0 || this.$refs.rXTable.tableData == null) {
                      var alld = this.$refs.lXTable.tableData;
                      var rowindex = alld.indexOf(this.selrow);
                      this.lXTableData.splice(rowindex, 1);
                  }
                  this.TplXTableData = XEUtils.clone(this.$refs.lXTable.getTableData().fullData);
                  this.actionindex = "M";
              } else {
                  this.$message.error("保存失败！" + res.errmsg);
              }
          } catch (e) {
              this.$message.error(e);
          }
      },
      //导出
      btnExport() {
          let p = { prgno: "LIS823" };
          this.$pub.commexport(this, p, `抗生素折点维护.dat`);
      },
      //导入 -- 暂无
      btnImport() {},
      //--------------- 数据改变及其他功能 ---------------//
      //行改变事件
      async CurrentChangeEvent({ row }) {
          if (this.bChangeFlag) {
              this.$refs.lXTable.setCurrentRow(this.selrow);
              return false;
          } else {
              await this.detailQuery(row);
          }
      },
      //保存后不刷新左侧主表,前台赋值。
      SetToTable(obj) {
          return new Promise((s, f) => {
              s(this.selrow);
              return;
          });
      },
      // 回车换行
      NextFocus(index) {
          if (index > 4) return false;
          var that = this;
          var focusIndex = index + 1;
          setTimeout(function () {
              that.$refs["input" + focusIndex].focus();
          }, 1);
      },
      activeMethod({ row }) {
          return true;
      },
      //数据发生改变 -- 获取数据改变
      GetChange(code, name) {
          this.HasChange();
      },
      //数据发生改变 -- 按钮禁用/可用切换
      HasChange() {
          this.bChangeFlag = true;
      },
      CalcRange({ row, column} ,val ){
          var secval= val.target.value;
          var field=column.property;
          if(field=="kbny") row.kbny=secval;
          if(field=="kbmg") row.kbmg=secval;
          if(field=="micny") row.micny=secval;
          if(field=="micmg") row.micmg=secval;
          if(field=="kbny" || field=="kbmg"){
              var kbny="";
              var kbmg="";
              var havesym = false;//输入的值是否带符号
              if(!!row.kbny){
                  if(row.kbny.indexOf('>')>-1 || row.kbny.indexOf('<')>-1 || row.kbny.indexOf('=')>-1)
                  {
                      kbny=row.kbny;
                      havesym=true;
                  }else{
                      kbny="<="+row.kbny;
                  }
              }
              if(!!row.kbmg){
                  if(row.kbmg.indexOf('>')>-1 || row.kbmg.indexOf('<')>-1 || row.kbmg.indexOf('=')>-1)
                  {
                      kbmg=row.kbmg;
                      havesym=true;
                  }else{
                      kbmg=">="+row.kbmg;
                  }
              }
              if(!!kbny && !!kbmg){
                  if(this.kbrange){
                      if(havesym){
                          row.kbrange=this.kbrange.replace(">=#S",kbmg).replace("<=#R",kbny);
                      }else{
                          row.kbrange=this.kbrange.replace("#S",row.kbmg).replace("#R",row.kbny);
                      }
                  }else{
                      row.kbrange=kbmg+";"+kbny;
                  }
              }else if(!!kbny){
                  row.kbrange=kbny ;
              }else if (!!kbmg){
                  row.kbrange=kbmg ;
              }else{
                  row.kbrange="" ;
              }
          }
          if(field=="micny" || field=="micmg"){
              var micny="";
              var micmg="";
              var havesym = false;//输入的值是否带符号
              if(!!row.micny){
                  if(row.micny.indexOf('>')>-1 || row.micny.indexOf('<')>-1 || row.micny.indexOf('=')>-1)
                  {
                      micny=row.micny;
                      havesym=true;
                  }else{
                      micny=">="+row.micny;
                  }
              }
              if(!!row.micmg){
                  if(row.micmg.indexOf('>')>-1 || row.micmg.indexOf('<')>-1 || row.micmg.indexOf('=')>-1)
                  {
                      micmg=row.micmg;
                      havesym=true;
                  }else{
                      micmg="<="+row.micmg;
                  }
              }
              if(!!micny && !!micmg){
                  if(this.micrange){
                      if(havesym){
                          row.micrange=this.micrange.replace(">=#S",micmg).replace("<=#R",micny);
                      }else{
                          row.micrange=this.micrange.replace("#S",row.micmg).replace("#R",row.micny);
                      }
                  }else{
                      row.micrange=micmg+";"+micny;
                  }
                  
              }else if(!!micny){
                  row.micrange=micny ;
              }else if (!!micmg){
                  row.micrange=micmg ;
              }else{
                   row.micrange="" ;
              }
          }
          this.HasChange();
      },
      //获取输入码
      CreateInputcode() {
          this.detailData.inputcode = this.$pub.CreateInputcode(this.detailData.medgroupname, this, 20);
      },
      //设置高亮选中行
      async HightLightRow(row) {
          if (!!row) {
              this.$refs.lXTable.setCurrentRow(row);
              await this.detailQuery(row);
          } else {
              this.$refs.lXTable.setCurrentRow(null);
              this.tempRow = {};
              this.detailData = {};
              this.tmpdetailData = {};
              this.rXTableData = [];
          }
      },
      //细菌类弹窗
      OpenGermDlg(row, flag) {
          //a
          // if (row.newrow != 1) {
          //     this.$message.info("菌科|菌属|细菌禁止修改，请通过点击新增按钮进行维护。");
          //     return false;
          // }
          if (!this.bChangeFlag) {
              this.newRowId = row._XID;
          } else {
              this.newRowId = row._XID;
          }
          if (this.bChangeFlag) {
              //编辑状态
              if (this.oldRowId != this.newRowId) return false; //rowId不相等 禁止编辑
          }
          this.germRow = row;
          if (flag == 1) {
              this.diagx = true;
              this.bDlgGermkind = true;
              this.$nextTick(() => {
                  this.$refs.refGermkind.loadAllData();
              });
          } else if (flag == 2) {
              this.kindno = row.germkind;
              this.diagx = true;
              this.bDlgGermgroup = true;
              this.$nextTick(() => {
                  this.$refs.refGermgroup.loadAllData();
              });
          } else if (flag == 3) {
              this.kindno = row.germkind;
              this.param1 = row.germgroup;
              this.diagx = true;
              this.bDlgGerm = true;
              this.$nextTick(() => {
                  this.$refs.refGerm.loadAllData();
              });
          }
      },
      // //抗生素类弹窗
      OpenMedDlg(row, flag) {
          this.medRow = row;
          if (flag == 1) {
              this.kindno = row.medclass2;
              this.param1 = row.medclass3;
              this.diagx = true;
              this.bDlgMed = true;
              this.$nextTick(() => {
                  this.$refs.refMed.loadAllData();
              });
          }
      },
      //菌科改变
      GermKindChange(c, v) {
          this.HasChange();
          //值
          this.germRow.orgcode = c;
          this.germRow.isgermgroup = 2;
          //显示
          this.germRow.germkind = c;
          this.germRow.germgroup = "";
          this.germRow.germ = "";
          this.germRow.germkindna = v;
          this.germRow.germgroupna = "";
          this.germRow.germna = "";
          setTimeout(() => {
              this.$refs.lXTable.setCurrentRow(this.selrow);
          }, 30);
          this.AddLastFocus();
          this.bDlgGermkind = false;
      },
      //菌属改变
      GermGroupChange(c, v) {
          this.HasChange();
          this.GKind("", c);
          //值
          this.germRow.orgcode = c;
          this.germRow.isgermgroup = 1;
          //显示
          this.germRow.germgroup = c;
          this.germRow.germ = "";
          this.germRow.germgroupna = v;
          this.germRow.germna = "";
          setTimeout(() => {
              this.$refs.lXTable.setCurrentRow(this.selrow);
          }, 30);
          this.AddLastFocus();
          this.bDlgGermgroup = false;
      },
      //细菌改变
      GermChange(c, v) {
          this.HasChange();
          this.GKind(c, "");
          this.GGroup(c);
          this.$nextTick(() => {
              //值
              this.germRow.orgcode = c;
              this.germRow.isgermgroup = 0;
              //显示
              this.germRow.germ = c;
              this.germRow.germna = v;
              setTimeout(() => {
                  this.$refs.lXTable.setCurrentRow(this.selrow);
              }, 30);
              this.AddLastFocus();
              this.bDlgGerm = false;
          });
      },
      //抗生素改变
      MedChange(c, v) {
          this.HasChange();
          this.$nextTick(() => {
              //值
              this.medRow.medcode = c;
              //显示
              this.medRow.medname = v + "[" + c + "]";
              // setTimeout(() => {
              //     this.$refs.lXTable.setCurrentRow(this.selrow)
              // }, 30)
              this.$refs.rXTable.setActiveCell(this.medRow, "medgroup");
              this.bDlgMed = false;
              this.isimportantmed(c);
          });
      },
      isimportantmed(medcode){
          let alldata=this.$refs.rXTable.getTableData().fullData;
          if(alldata.filter((item)=> item.medcode==medcode && item.isimportant=='1').length>0){
              this.medRow.isimportant="1";
          }else{
              var lselrow =this.$refs.lXTable.getCurrentRow();
              if(lselrow){
                  this.$tool
                  .request({
                      url: "LIS/LIS8/LIS823",
                      method: "post",
                      data: {
                          action: "isimportantmed",
                          medcode: this.medRow.medcode,
                          isgermgroup: lselrow.isgermgroup == 0 ? "" : lselrow.isgermgroup,
                          orgcode: lselrow.orgcode,
                      },
                  })
                  .then((res) => {
                      if(res.errcode=="1"){
                          this.medRow.isimportant=res.isimportant;
                      }else{
                          this.medRow.isimportant="0";
                      }
                  })
                  .catch((e) => {
                      console.log(e);
                  });
              }
              
          }
      },
      //新增/删除明细
      OpenDialog(type) {
          let row = this.$refs.lXTable.getCurrentRow();
          if (!row) return false;
          if (type == 1) {
              this.$refs.rXTable
                  .insert({
                      i2sdd: 0,
                      orgcode: this.selrow.orgcode,
                      isgermkind: this.selrow.isgermgroup == "2" ? 1 : 0,
                      specimen_code: "All",
                  })
                  .then(({ row }) => {
                      this.$refs.rXTable.setCurrentRow(row);
                      this.bChangeFlag = true;
                  });
          } else if (type == 2) {
              try {
                  var delrow = this.$refs.rXTable.getCurrentRow();
                  if (delrow) {
                      var alld = this.$refs.rXTable.tableData;
                      var rowindex = alld.indexOf(delrow);
                      this.$refs.rXTable.remove(delrow);
                      let havedata = this.$refs.rXTable.tableData;
                      this.bChangeFlag = true;
                      if (havedata.length > 0) {
                          if (rowindex >= havedata.length) rowindex = havedata.length - 1;
                          let selectrow = havedata[rowindex];
                          this.$refs.rXTable.setCurrentRow(selectrow);
                      } else {
                          this.$refs.rXTable.setCurrentRow(null);
                      }
                  }
              } catch (e) {
                  this.$alert(e, "error");
              }
          }
      },
      copyPaste(type) {
          if (type == 1) {
              let medList = this.$refs.rXTable.getTableData().fullData;
              this.copyMedlist = XEUtils.clone(medList, true);
          } else if (type == 2) {
              if (this.copyMedlist.length > 0) {
                  var that = this;
                  that.copyMedlist.forEach((element) => {
                      that.$refs.rXTable.insert({
                          ...element,
                          i2sdd: 0,
                          orgcode: that.selrow.orgcode,
                          isgermkind: that.selrow.isgermgroup == "2" ? 1 : 0,
                          specimen_code: "All",
                      }).then(({ row }) => {
                          that.$refs.rXTable.setCurrentRow(row);
                          that.bChangeFlag = true;
                      });
                  });
              }
          }
      },
      FunscrollY() {
          this.$nextTick(() => {
              var alldataLen = this.$refs.lXTable.tableData.length;
              let L = this.$refs.lXTable.tableData[alldataLen - 1];
              this.selrow = L;
              this.$refs.lXTable.setCurrentRow(L);
              // this.$refs.lXTable.setActiveCell(L, 'germkindna')
              this.$refs.lXTable.scrollToRow(L);
              this.oldRowId = XEUtils.clone(L._XID, true);
              this.tempRow = XEUtils.clone(L, true);
              this.ntempRow = L;
              if (this.AddData.indexOf(L.medcode) == -1) this.AddData.push(L);
          });
      },
      RFunscrollY() {
          var alldataLen = this.$refs.rXTable.tableData.length;
          let L = this.$refs.rXTable.tableData[alldataLen - 1];
          this.selrow = L;
          this.$refs.rXTable.scrollToRow(L);
          this.$refs.rXTable.setCurrentRow(L);
          this.$refs.rXTable.setActiveCell(L, "medname");
          this.$refs.rXTable.scrollToRow(L);
      },
      AddLastFocus() {
          if (this.actionindex == "A") {
              this.$refs.rXTable.setActiveCell(this.$refs.rXTable.getTableData().fullData[this.$refs.rXTable.getTableData().fullData.length - 1], "medname");
          }
      },
      GoTopMedGroup() {
          this.$refs.rXTable.setActiveCell(row, "medgroup");
      },
      //----------------- class -----------------//
      //左侧主表 row class
      LRowClassName({ row, rowIndex }) {
          let isDirty = this.$refs.lXTable.hasRowChange(row);
          if (isDirty) {
              return "row-modify";
          }
          if (this.$refs.lXTable.hasRowInsert(row)) {
              return "row-new";
          }
      },
      //右侧子表 row class
      RRowClassName({ row, rowIndex }) {
          if (row.stopflag == "1") {
              return "rm-alert";
          }
          let isDirty = this.$refs.rXTable.hasRowChange(row);
          if (isDirty) {
              return "row-modify";
          }
          if (this.$refs.rXTable.hasRowInsert(row)) {
              return "row-new";
          }
      },
      lCellClassName({ row, rowIndex, $rowIndex, column }) {
          if (column.property == "germkind") {
              if (row.isgermgroup == 1) {
                  return "isOrgcode";
              }
          } else if (column.property == "germgroup") {
              if (row.isgermgroup == 2) return "isOrgcode";
          } else if (column.property == "germ") {
              if (row.isgermgroup == 3) return "isOrgcode";
          }
      },
      btnmedCopy(){
          this.$pub.medgroupcopy={};
          this.$pub.medgroupdetailcopy=[];
          var currentrow=this.$refs.lXTable.getCurrentRow();
          if(currentrow){
              this.$pub.medgroupcopy=XEUtils.clone(currentrow,true);
          }
          if(this.rXTableData){
              this.$pub.medgroupdetailcopy=XEUtils.clone(this.rXTableData,true);
          }
          this.$confirm("复制成功,点击确定跳转到粘贴页面。", {
              confirmButtonText: "确定",
              cancelButtonText: "取消",
              type: "warning",
          })
              .then(() => {
                  this.$router.push("/LIS827");
                  
              })
              .catch(() => {
                  //this.$message.info("取消保存");
              });
      }
  },
};
</script>

<style scoped>
.pagetop {
  width: 100%;
  height: 105px;
  display: -webkit-box;
  -webkit-box-pack: left;
  -webkit-box-align: center;
  border: 1px solid #ccc;
  position: absolute;
  z-index: 99;
}

.pagecenter {
  position: absolute;
  top: 110px;
  width: 100%;
  left: 0;
  bottom: 0px;
  overflow: auto;
}

.middle-center {
  position: absolute;
  height: 100%;
  left: 0px;
  right: 49%;
  overflow: auto;
  border: 1px solid #ccc;
}

.middle-right {
  position: absolute;
  height: 100%;
  /* width: 50%; */
  left: 51%;
  padding-left: 3px;
  right: 0px;
  border: 1px solid #ccc;
}

.search-title {
  margin: 0 0 0 5px;
  font-size: 12px;
  position: absolute;
  top: 7px;
  display: flex;
  align-items: center;
}
.top-deal {
  right: 5px;
  position: absolute;
  top: 5px;
  display: flex;
  align-items: center;
}
.detailxTable {
}
/deep/.el-textarea__inner {
  display: block;
  resize: vertical;
  padding: 2px 4px;
}
/deep/ .el-button.is-disabled {
  border: 0px;
  color: grey;
  background-color: #e6e6e6;
  font-weight: normal;
}
/deep/ tr.vxe-body--row.row-modify {
  color: blue;
}
/deep/ tr.vxe-body--row.row-new {
  color: #cc6600;
}
/deep/.vxe-cell.isOrgcode {
  background-color: #cc6600;
  color: blue;
  font-weight: bold;
}
/deep/ tr.vxe-body--row.row--current {
  color: #000000;
  font-weight: bold;
}
.table1style tr td {
  padding: 0px 2px 0px 2px;
}
</style>

